#******************************************************************
#
# Copyright 2016 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

import os

Import('env')

mediator_env = env.Clone()

target_os = env.get('TARGET_OS')

######################################################################
# Build flags
######################################################################

if env.get('RELEASE'):
    mediator_env.AppendUnique(CCFLAGS=['-Os'])
else:
    mediator_env.AppendUnique(CCFLAGS=['-g'])

mediator_env.AppendUnique(CPPDEFINES=['CPP_MEDIATOR'])

if target_os not in ['windows']:
    mediator_env.AppendUnique(CXXFLAGS=['-Wall', '-std=c++0x'])

mediator_env.PrependUnique(CPPPATH=[
    '#/resource/include',
    '#/resource/oc_logger/include',
    '#/resource/c_common',
    '#/resource/c_common/ocrandom/include',
    '#/resource/c_common/oic_malloc/include',
    '#/resource/c_common/oic_string/include',
    '#/resource/csdk/include',
    '#/resource/csdk/stack/include',
    '#/resource/csdk/security/provisioning/include',
    '#/resource/csdk/security/provisioning/include/internal',
    '#/resource/csdk/logger/include',
    '#/resource/csdk/security/include',
    '#/resource/csdk/connectivity/api',
    '#/extlibs/cjson',
    '#/service/easy-setup/mediator/richsdk/inc',
    '#/service/easy-setup/mediator/richsdk/src',
    '#/service/easy-setup/inc',
])

mediator_env.PrependUnique(LIBS=['ESMediatorRich'])

if env.get('SECURED') == '1':
    mediator_env.AppendUnique(LIBS=[
        'ocpmapi',
        'ocprovision',
        'mbedtls',
        'mbedx509',
        'mbedcrypto',
    ])

mediator_env.AppendUnique(LIBS=['oc',
    'octbstack',
    'oc_logger',
    'connectivity_abstraction',
])

mediator = mediator_env.Program('mediator', 'mediator.cpp')
submediator = mediator_env.Program('submediator', 'submediator.cpp')

submediator += mediator_env.ScanJSON('service/easy-setup/sampleapp/mediator/linux/richsdk_sample')

Alias('mediator_rich', submediator)
env.AppendTarget('mediator_rich')
examples = [mediator, submediator]
mediator_env.UserInstallTargetExtra(examples)
